package com.cskaoyan.servlet;

import com.cskaoyan.bean.vo.GoodsVo;
import com.cskaoyan.service.GroupGoodsService;
import com.cskaoyan.service.GroupGoodsServiceImpl;
import com.cskaoyan.util.JacksonUtil;
import com.cskaoyan.util.ResponseUtil;
import com.cskaoyan.util.URIUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/goods/create")
public class GroupGoodsCreateServlet extends WdBaseServlet {

    private GroupGoodsService groupGoodsService = new GroupGoodsServiceImpl();


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String operation = URIUtil.getOperation(this.getClass(),request);
//        switch (operation) {
//            case "/create":
        create(request, response);
//                break;
//        }
    }
    // /admin/goods/create
    private void create(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String jsonStr = request.getReader().readLine();
        GoodsVo goodsVo = JacksonUtil.read(jsonStr, GoodsVo.class);
        ResponseUtil.responseJson(response,groupGoodsService.create(goodsVo));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

